<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>工程材料需求申请单管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../resources/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../resources/css/style.css" media="all">
    <style>
        .layui-form-label{width: 100px; height: 20px;}
        .layui-form-select{width: 190px;}
        #gonghuoshijian{ width: 100%;}
        .addUser input{width: 86%;}
        .layui-form-select{width: 100%!important;}
        .layui-form-select input{width: 100%;}
        .layui-form-item{padding-left: 70px;}
        .layui-form-item .layui-input-inline{width: 50%!important;}
        .masksx{width: 800px;}
        .material{display: flex;justify-content: flex-start;margin-bottom: 8px;width: 100%;}
        .material label{float: left;height: 38px;line-height: 38px; display: inline-block;width: 100px;}
        ._mater{width: 49%;margin-left: 30px;}
        .layui-form-select .layui-input{padding-right: 0;}
        ._materwarp{width: 43%;}
        .masksx .forms{padding-left: 78px;}
        .material ._mater_input{width: 10%;}
        ._mater_lab{margin:0 20px;}
        .addTo{background-color: #86B1FC;color: #FFF; width: 10px;height: 10px;display: none}
        .materialone .addTo{display:inline;}
        .mater_btn{margin: 6px 0 0 6px;}
        .material_C{width: 100px;text-align: justify;}
        .material_C:after{content:'';width: 100%;display: inline-block;}
        .materialone .mater_btn{display: none;}
        .forms{padding-top: 20px;}
        @media screen and (max-width: 768px){
            .MOVE_queryon .layui-form-item {
                width: 80%;
            }
            .layui-form-item{padding: 0;}
            .MOVE_footer{text-align: right;}
            .MOVE_footer a{color: #FFF;font-size: 20px;line-height: 30px;
                padding: 10px;background-color: #F5A721;height: 100%;position: absolute;right: 0;}
        }
        .layui-form-pane .layui-input-inline{width: 80%;}
        .masksx{height: 80%;}
        .forms{height: 76%;}
        .mask .layui-inline{padding-left: 0;width: 100%;}
        .forms{padding-left: 0px!important; position: absolute;left: 60px;}
        .mask .forms .layui-form-item{width: 48%;padding-left: 0; display: inline-block;}
        .mask .forms .layui-input-inline{width: 70%;}
        .mask .forms .layui-input-inline input {width: 100%!important;}
        .bixuan{left: 4px;}
        ._mater{width: 55%!important;}
        .masksx .layui-form-item{margin-bottom: 10px;}
        .layui-form-selected dl{z-index: 9999;height: 120px;}
        /*.erpmask { width: 70%;}*/
        /*.erpmask .forms{ padding-left:0;}*/
        .Red{color: red;}

    </style>
</head>
<body>
<div class="_PC">
    <a class="dayin" type="button" id="dlink"  style="float: right; position: fixed; right: 50px; bottom: 50px; z-index: 999;"></a>
    <form class="layui-form layui-form-pane" id="form_7grid" action="" lay-filter="hetong">
        <div class="formTop">
            <div class="layui-inline layui-col-lg2 layui-col-md2 layui-col-xs2">
                <div class="layui-input-inline" style="width: 80%; ">
                    <input type="text" name="username" lay-verify="required" placeholder="工程名" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline layui-col-lg2 layui-col-md2 layui-col-xs2">
                <div class="layui-input-inline" style="width: 80%; ">
                    <input type="text" name="sqr" lay-verify="required" placeholder="请输入申请人" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline layui-col-lg2 layui-col-md2 layui-col-xs2">
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="test-limit3" placeholder="请输入开始日期">
                    <div class="icons">
                    </div>
                </div>
            </div>
            <div class="layui-inline layui-col-lg2 layui-col-md2 layui-col-xs2">

                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="test-limit4" placeholder="请输入结束日期">
                    <div class="icons">
                    </div>
                </div>
            </div>
            <div class="layui-inline layui-col-lg3 layui-col-md3 layui-col-xs3" >
                <button class="layui-btn tijiao" type="button" onclick="query()">查询</button>
                <button class="layui-btn layui-btn-danger quanxian" type="button" onclick="tianjiacailiao()" QX="api/ctteam/addMatFeed.do">材料申请</button>
            </div>

        </div>
        <table id="demo" lay-filter="test"></table>
        <script type="text/html" id="barDemo">

            <a class="layui-btn layui-btn-sm layui-btn-danger bianji quanxian" lay-event="edit" QX="api/ctteam/updateMatFeed.do">编辑</a>
            <a class="layui-btn layui-btn-sm xiangqing quanxian" lay-event="detail" QX="api/material/loadMatFeedPic.do">详情</a>
        </script>
        <!--<script type="text/html" id="titleTpl">-->

        <!--<span>{{times(1510635999999)}}</span>-->

        <!--</script>-->
    </form>
    <div id="demo7"></div>

    <div class="mask">
        <div class="masksx erpmask">
            <div class="title"><span class="titleL">材料申请</span><span class="close">×</span></div>
            <div class="forms">
                <form class="layui-form addUser" method="post" action="">

                    <!--<div class="layui-form-item">-->
                        <!--<label class="layui-form-label">申请单单号<span class="maohao">：</span></label>-->
                        <!--<div class="layui-input-block">-->
                            <!--<input type="text" name="feed_Code" lay-verify="required" autocomplete="off" placeholder="请输入" class="layui-input" value="">-->
                            <!--<input type="hidden" name="sup_Code" autocomplete="off" class="layui-input" value="">-->
                        <!--</div>-->
                    <!--</div>-->
                    <div class="layui-inline" style="margin-bottom: 10px;">
                        <label class="layui-form-label"><span class="bixuan">*</span>项目名称</label>

                        <div class="layui-input-inline" style="width: 74%;">
                            <select name="cc_UUID" lay-verify="required" lay-search=""  lay-filter='filter'>
                                <option value="">直接选择或搜索选择</option>

                            </select>
                        </div>
                    </div>
                    <div class="layui-inline" style="margin-bottom: 10px;">
                        <label class="layui-form-label"><span class="bixuan">*</span>收货地址及联系方式</label>

                        <div class="layui-input-inline" style="width: 74%;">
                            <textarea class="layui-textarea" name="f_adr" lay-verify="required" placeholder="请您务必输入收货地址及联系方式"></textarea>
                        </div>
                    </div>

                    <div class="layui-form-item" style="float: left;width: 50%;">
                        <label class="layui-form-label"><span class="bixuan">*</span>供货时间:</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="supply_Time" lay-verify="required" id="gonghuoshijian" placeholder="yyyy-MM-dd" style="width: 90%!important;">

                        </div>
                    </div>
                    <div class="layui-form-item" style="margin-left: 10px;">
                        <label class="layui-form-label"><span class="bixuan">*</span>申请人<span class="maohao">：</span></label>
                        <div class="layui-input-block">
                            <input type="text" name="feed_sqr" lay-verify="required" autocomplete="off" placeholder="请输入" class="layui-input" value="">
                        </div>
                    </div>

                    <div class="material materialone layui-col-xs12 layui-col-sm12 layui-col-md12">
                        <div class="layui-inline _materwarp" style="width:40%;">
                            <label class="material_C"><span class="addTo">+</span>材料名:</label>
                            <div class="layui-input-inline _mater">
                                <select name="modules" lay-verify="required"  lay-filter="xiala" lay-search="" class="modules">
                                    <option value=""> </option>
                                </select>
                            </div>
                        </div>
                        <label class="_mater_lab" style="width: 50px;margin: 0; text-align: center;">数量:</label>
                        <input type="number" name="username" lay-verify="required" placeholder="" autocomplete="off" class="layui-input _mater_input" style="width:20%!important;">
                        <label class="_mater_lab" style="margin: 0;text-align: center;">计量单位:</label>
                        <input type="text" name="cailiao" lay-verify="required" placeholder="" autocomplete="off" class="layui-input _mater_input" style="width:11%!important;">
                        <button class="layui-btn layui-btn-xs  layui-btn-normal mater_btn" type="button"><i class="layui-icon">&#xe640;</i>  </button>
                    </div>



                    <input type="hidden" name="cc_UUID" value="" />
                    <input type="hidden" name="sup_Code" value="" />


                    <div class="_submit">
                        <button class="layui-btn layui-btn-sm  tijiao" lay-submit lay-filter="_subm">提交</button>
                        <button class="layui-btn layui-btn-sm chongzhi" type="reset">重置</button>
                    </div>

                </form>

            </div>

        </div>

    </div>


</div>



<script src="../../../resources/layui/layui.js" charset="utf-8"></script>
<script src="../../../resources/js/style.js"></script>
<script src="../../../resources/js/api.js"></script>
<script>

    function query() {
        layui.use(['form', 'layedit', 'laydate','table','element'], function() {
            var form = layui.form
                , table = layui.table;
            var pronName=$("[name='username']").val();
            var begintime=$('#test-limit3').val();
            var endtime=$('#test-limit4').val();
            var shenqingren=$('[name="sqr"]').val();

            if(!AntiSqlValid(pronName)){
                if(lbq('api/material/loadMatFeedPic.do')) {

                    API.xuqiushenqing({
                        'type': 'a',
                        'proName': pronName,
                        'begintime': begintime,
                        'endtime': endtime,
                        'sqr': shenqingren,
                        'p': getCookie('yanzheng')
                    })
                }
            }else {
                layer.msg('请勿输入特殊符号');
            };
        })

    }
    function tianjiacailiao() {
        $('.mask').show();
        $('.mask input').val('');
        $('.mask select').val('');
        var cooks=getCookie('yanzheng')
        cooks=cooks.split('|');
        $('[name="feed_sqr"]').val(cooks[0])
        $('.dingshiqingchu').remove();
        $('.tijiao').attr('lay-filter',"_subm")
        $('.chongzhi').show();
        $('.material').each(function (k) {
            if(k!=0){
                $(this).remove();
            }
        })

    }




    layui.use(['form', 'layedit', 'laydate','table','element','laypage','flow'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate
            ,table=layui.table
            ,laypage=layui.laypage
            ,flow=layui.flow
            ,element=layui.element;
        var canshu=new Object();
        jiazais();
        var _dom;
        ajaxs('/api/public/loadPriDropDown.do','post',{'type':'d','p':getCookie('yanzheng')},function (data) {
            console.log(data)
            var datas=data.data;
            for(var i=0;i<datas.length;i++){
                $('[name="cc_UUID"]').append('<option value="'+datas[i].cc_UUID+'">'+datas[i].proName+'</option>')
                canshu[datas[i].cc_UUID]={'names':datas[i].eppStaEnd}
            };

            form.render();
        })

        laydate.render({
            elem: '#gonghuoshijian' //指定元素
            ,type: 'datetime'
        });
        var n=0;
        var nums=0;
        form.on('select(xiala)', function(data){
            console.log(data.elem); //得到select原始DOM对象
            console.log(data.value); //得到被选中的值
            console.log(data.othis); //得到美化后的DOM对象
            var datas=data.elem;
            var danwei=$(datas).find("option:selected").attr('cailiao');
            var shangfu=$(datas).find("option:selected").attr('mat-type');
            console.log($(datas).parent().parent().parent().children('[name="cailiao"]'));
            $(datas).parent().parent().parent().children('[name="cailiao"]').val(danwei);
            var time = 0;
            var mats=$(datas).find("option:selected").attr('mat-type');
            $(datas).parents('._materwarp').next().next().attr('mat-type',mats);

            form.render();
        });

        $(document).on('click','.mater_btn',function () {
            $(this).parent().remove();
        });

        $('.close').click(function () {     //遮罩层隐藏
            $('.mask').hide();
        });

        //下拉监听
        form.on('select(filter)', function(data){
            console.log(data.elem); //得到select原始DOM对象
            console.log(data.value); //得到被选中的值
            console.log(data.othis); //得到美化后的DOM对象
            console.log(canshu)
            for(var key in canshu){
                console.log(key)
                if(data.value==key){
                    $('[name="f_adr"]').val(canshu[key].names);
                    sessionStorage.cc_UUID=key;
                    console.log(sessionStorage.cc_UUID)
                }
            }

        });

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        //执行渲染
        if(lbq('api/material/loadMatFeedPic.do')){
            API.xuqiushenqing({'type':'a','p':getCookie('yanzheng')});

        }
//
        //前后若干天可选，这里设置不能选过去的日期      最远可选1000天之后
        panduanshijiantow('#test-limit3','#test-limit4',1000,1000,'.tijiao');     //查询 开始结束时间判断

        ajaxs('/api/public/loadPriDropDown.do','post',{'type':'b','p':getCookie('yanzheng')},function (data) {
            console.log(data);
            var datas=data.data;
            for(var i=0;i<datas.length;i++){
                $('.modules').append('<option value="'+datas[i].mat_id+'" cailiao="'+datas[i].mat_Bit+'" mat-type="'+datas[i].mat_Type+'">'+datas[i].mat_Name+'</option>');
            }
            _dom=$('.materialone').html();

            form.render();
        });

        $(document).on('blur','[type="number"]',function () {
            if($(this).val()<0){
                layer.msg('数量不能小于0');
                $(this).val(0);
            }
        });



        //监听工具条
        table.on('tool(test)', function(obj){ //注<span class="maohao">：</span>tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值
            var tr = obj.tr; //获得当前行 tr 的DOM对象

            if(layEvent === 'detail'){ //查看
                //do somehing
                console.log(obj)
                sessionStorage.xiangqing=obj.data.feed_Code;
                location.href='./detail.html'
            }else if(layEvent === 'edit'){ //编辑
                $('.chongzhi').hide();
                //do something
                console.log(obj)
                $('.tijiao').attr('lay-filter','_subm2')
                sessionStorage.feed_Codeone=obj.data.feed_Code;
                $('.mask').show();
                $('.titleL').html('材料申请单修改')
                $('.mask input').val('');
                $("[name='cc_UUID']").val(obj.data.cc_UUID);
                $('#gonghuoshijian').val(obj.data.supply_Time);
                $("[name='feed_sqr']").val(obj.data.feed_sqr);
                $("[name='f_adr']").val(obj.data.f_adr);
                $('.material').each(function (k,v) {
                    if(k!=0){
                        $(this).remove();
                    }
                });

                ajaxs('/api/material/loadMatFeedPic.do','post',{'type':'b','feed_code':obj.data.feed_Code,'p':getCookie('yanzheng')}, function(data){
                    console.log(data,'>>>>>>>>>>>>>>>>>>>>')
                    var datas=data.data;
                    var html=$('.material').html();
//                    console.log(html)
                    $('.dingshiqingchu').remove();
                    for(var i=0;i<datas.length;i++){
                        if(i==0){
                            $('.material').eq(i).find($('[name="modules"]')).val(datas[i].mat_id);
                            $('.material').eq(i).find($('[name="username"]')).val(datas[i].feed_Num).attr({'mat-type':datas[i].mat_Type,'matid':datas[i].mat_id});
                            $('.material').eq(i).find($('[name="cailiao"]')).val(datas[i].mat_bit);
                        }else{
                            console.log($('.material').eq(i))
                            $('._submit').before('<div class="material dingshiqingchu layui-col-xs12 layui-col-sm12 layui-col-md12">'+html+'</div>');
                            $('.material').eq(i).find($('[name="modules"]')).val(datas[i].mat_id);
                            $('.material').eq(i).find($('[name="username"]')).val(datas[i].feed_Num).attr({'mat-type':datas[i].mat_Type,'matid':datas[i].mat_id});
                            $('.material').eq(i).find($('[name="cailiao"]')).val(datas[i].mat_bit);

                        }

                        $('.tijiao').attr('lay-filter',"_subm2")
                    }
                    $('[name="modules"]').each(function (k,v) {
                        console.log($(v).val())
                        if($(v).val()==168){
                            $(v).attr('disabled','disabled');
                            $(v).parents('.material').addClass('yunfei');
                            $(v).parents('.material').children('[name="username"]').attr('disabled','disabled');
                        }
                    })
                    $('.yunfei').children('.mater_btn').remove();

                    form.render();
                })

                form.render();
            }else if(layEvent==='shenqing'){
                console.log(obj)
                $('.mask').show();
                $('.mask input').val('');

                $("[name='cc_UUID']").val(obj.data.cc_uuid);
                $("[name='sup_Code']").val(obj.data.compid);
            }
        });
        var p=true;

        form.on('submit(_subm)',function (data) {
            var panduans=true;
            console.log(data.field)
            var cailiao='';
            var n=0;
            $('.mask [name="username"]').each(function () {
                console.log($(this).attr('mat-type'))
                if($(this).val()==0){
                    layer.msg('申请材料数不能小于1');
                    panduans=false;
                    return;
                }
                var m=$(this).attr('mat-type');

                //todo:2018-3-27 10:11:21去掉的
                /*if(m==1){
                    n+=parseInt($(this).val());
                    if(n<3&&p){
                        layer.msg('上覆材料类总量少于3，需支付运费');
                        panduans=false;
                        $('.material:last').after('<div class="material yunfei layui-col-xs12 layui-col-sm12 layui-col-md12">'+_dom+'</div>');
                        $('.yunfei').children().children('._mater').children().val(168).attr('disabled','disabled');
                        $('.yunfei').children('[name="username"]').val(1).attr('disabled','disabled');
                        $('.yunfei').children('[name="cailiao"]').val('次').attr('disabled','disabled');
                        $('.yunfei').children('.mater_btn').remove();
                        p=false;
                        form.render();
                    }else if(n>=3){
                        $('.yunfei').remove();
                        p=true;
                    }
                }*/
            });

            $('.material').each(function () {
                cailiao+=$(this).children().children('._mater').children('.modules').val()+','+$(this).children('._mater_input').val()+'|';

            })


            cailiao=cailiao.substr(0,cailiao.length-1);
            console.log(cailiao)
            data.field.sd=cailiao;
            data.field.p=getCookie('yanzheng');
            data.field.cc_UUID=sessionStorage.cc_UUID;
            if(panduans){
                formAlertAjax('/api/ctteam/addMatFeed.do',data.field,'.tijiao');
            }

            return false;
        });
        var s=true;

        form.on('submit(_subm2)',function (data) {
            console.log(data.field)
            var cailiao='';
            var n=0;
            var panduans=true;
            var c=true;
            $('.mask [name="username"]').each(function () {
                console.log($(this).attr('mat-type'))
                if($(this).val()==0){
                    layer.msg('申请材料数不能小于1');
                    panduans=false;
                    return;
                }
                var m=$(this).attr('mat-type');
                if($(this).attr('matid')==168){
                    return;
                }
                //todo:2018-3-27 10:12:01去掉的
                /*if(m==1){
                    c=false;
                    n+=parseInt($(this).val());

                    if(n<3&&s){
                        layer.msg('上覆材料类总量少于3，需支付运费');
                        panduans=false;
                        if($('.yunfei').length==0){
                            $('.material:last').after('<div class="material yunfei layui-col-xs12 layui-col-sm12 layui-col-md12">'+_dom+'</div>');
                            $('.yunfei').children().children('._mater').children().val(168).attr('disabled','disabled');
                            $('.yunfei').children('[name="username"]').val(1).attr('disabled','disabled');
                            $('.yunfei').children('[name="cailiao"]').val('次').attr('disabled','disabled');

                        };
                        console.log(  $('.yunfei').children('button'),'?>?<>?<>?><>>?');
                        s=false;
                        form.render();
                    }else if(n>=3){
                        $('.yunfei').remove();
                        s=true;
                    }
                }*/
            });
            if(c){
                $('.yunfei').remove();
            }
            $('.material').each(function () {
                cailiao+=$(this).children().children('._mater').children('.modules').val()+','+$(this).children('._mater_input').val()+'|';
            });

            cailiao=cailiao.substr(0,cailiao.length-1);
            console.log(cailiao)
            data.field.sd=cailiao;
            data.field.p=getCookie('yanzheng');
            data.field.cc_UUID=$('[name="cc_UUID"]').val();
            data.field.feed_Code=sessionStorage.feed_Codeone;
            Btnon('.tijiao');
            if(panduans){
                formAlertAjax('/api/ctteam/updateMatFeed.do',data.field,'.tijiao');
            }else{
                Btnoff('.tijiao');
            }

            return false;
        })

        $("[name='feed_Code']").blur(function () {
            console.log($(this).val()!= $("[name='namespan']").val())
            if($(this).val()== $("[name='namespan']").val()){
                return;
            }
            ajaxs('/api/public/cheName.do','get',{'type':3,'name':$(this).val()},function (data) {
                console.log(data)
                if(data.code==0){
                    if(data.data=='1'){
                        layer.msg('申请单号已存在 请重新输入');
                        $('.tijiao').attr('disabled','true').addClass('layui-btn-disabled');//禁止提交按钮点击
                    }else{
                        $('.tijiao').removeAttr('disabled').removeClass('layui-btn-disabled');//禁止提交按钮点击

                    }

                }
            })
        })
        dayintishi('.dayin');


        //材料添加
        $('.material_C').click(function () {

            $('.materialone').after('<div class="material layui-col-xs12 layui-col-sm12 layui-col-md12">'+_dom+'</div>');
            form.render();
        })

        $('[name="cailiao"]').attr('disabled','disabled')


    })

</script>
</body>
</html>